package com.fdb.efp.nls.service.util;

import com.fdb.efp.nls.common.bo.UpLoadFileVO;
import com.sunyard.client.bean.ClientFileBean;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.function.Predicate;

/**
 * primerxiaod htd
 */
public class ProtocolFileUploadUtil {

    /**
     * 预言一个list为空
     */
    public static Predicate<List> emptyListPredicate=(ls)-> {
        if (ls==null) {
            return true;
        }

        if (ls.size()<1) {
            return true;
        }

        for (Object l : ls) {
            if (l != null) {
                return false;
            }
        }

        return true;
    };

    /**
     * 预言uploadfilevo为空
     */
    public static Predicate<UpLoadFileVO> emptyUpLoadFileVOPredicate=(upLoadFileVO)-> upLoadFileVO==null|| StringUtils.isEmpty(upLoadFileVO.getApplySeq());

    /**
     * 预言clientfilebean为空
     */
    public static Predicate<ClientFileBean> emptyClientFileBeanPredicate=(clientFileBean)-> clientFileBean==null;

    /**
     * 获取处理日期
     * @return 年月日 如：20190515
     */
    public static String getBatchDate() {
        return  LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
    }

    /**
     * 解释影像系统返回报文到对象
     * @param msg
     * @return
     */
    public static UploadRtMsg explainMsg(String msg){

        UploadRtMsg uploadRtMsg=new UploadRtMsg();
        uploadRtMsg.setMsg(msg);
        String[] msgArr = msg.split("<<::>>");
        if ("SUCCESS".equalsIgnoreCase(msgArr[0])) {
            uploadRtMsg.setSuccess(true);
            if (msgArr.length > 1) {
                uploadRtMsg.setBatch(msgArr[1]);
            }
            if (msgArr.length>2) {
                try {
                    uploadRtMsg.setRetCode(Integer.parseInt(msgArr[2]));
                 } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else {
            uploadRtMsg.setSuccess(false);
            uploadRtMsg.setMsg(msg);
        }
        return uploadRtMsg;
    }

}
